package com.bhs.sansong.ui.order;

import static com.google.android.material.tabs.TabLayout.MODE_SCROLLABLE;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.viewpager2.widget.ViewPager2;

import com.bhs.sansong.R;
import com.bhs.sansong.adapter.FragmentAdapter;
import com.bhs.sansong.base.BaseFragment;
import com.bhs.sansong.bean.TabBean;
import com.bhs.sansong.view.SelectedFont3;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

/**
 * 发货单
 */
public class ShipmentsOrderFragment extends BaseFragment {

    private final List<TabBean> tabBeanList = new ArrayList<>();
    private TabLayout mTabLayout;
    private ViewPager2 mViewPage;


    public static ShipmentsOrderFragment newInstance() {
        return new ShipmentsOrderFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public int initLayout() {
        return R.layout.fragment_shipments_order;
    }

    @Override
    public void initView(View root) {
        mTabLayout = root.findViewById(R.id.tabLayout);
        mViewPage = root.findViewById(R.id.view_page);
        tabBeanList.add(new TabBean("全部", ""));
        tabBeanList.add(new TabBean("待付款", "0"));
        tabBeanList.add(new TabBean("有回单", "101"));
        tabBeanList.add(new TabBean("已完成", "15,20"));
        tabBeanList.add(new TabBean("已取消", "99"));
    }

    @Override
    public void initData() {
        mTabLayout.setTabMode(MODE_SCROLLABLE);
        //tab切换时候的字体设置
        mTabLayout.addOnTabSelectedListener(new SelectedFont3(activity));
        ArrayList<BaseFragment> fragments = new ArrayList<>();
        for (TabBean tabBean : tabBeanList) {
            fragments.add(OrderGoodsListFragment.newInstance("1", tabBean.getType()));
        }
        mViewPage.setOffscreenPageLimit(fragments.size());
        mViewPage.setAdapter(new FragmentAdapter(activity, fragments));
        new TabLayoutMediator(mTabLayout, mViewPage, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(tabBeanList.get(position).getTypeName());
            }
        }).attach();
    }
}